<template>
  <div>
    <p>1.获取所有图书信息</p>
    <button @click="getBook">axios发起get无参请求</button><br>

    <!-- <p>2.查询某本书籍信息</p>
    <input type="text" placeholder="请输入你想查询的书名" v-model="bName" />
    <button @click="getBook">axios发起get有参请求</button> -->

    <input type="text" placeholder="请输入书名" v-model="bookObj.bookname"><br>
    <input type="text" placeholder="请输入作者" v-model="bookObj.author"><br>
    <input type="text" placeholder="请输入出版社" v-model="bookObj.publisher"><br>
    <button @click="addBook">添加书籍</button>

  </div>
</template>

<script>
// import axios from "axios";
import axios from "./Utils/request"

export default {
  data() {
    return {
      bName: "",
      bookObj: {
        bookname: '',
        author : '' ,
        publisher: ''
      }
    };
  },
  methods: {
    getBook() {
      //获取无参请求
      axios.get('/api/getbooks').then(res =>{
        console.log(res);
      })

      // //获取有参请求
      // axios
      //   .get("/api/getbooks", {
      //     params: {
      //       bookname: this.bName,
      //     },
      //   })
      //   .then((res) => {
      //     console.log(res);
      //   });
    },
    addBook (){
      axios.post('/api/addbook',{
        appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
        ...this.bookObj
      })
       .then((res) => {
          console.log(res);
        });
    }
  },
};
</script>

<style>
</style>